% GAUTIER LE BIHAN - 2020
% Replication files for "Shocks vs Menu Costs: Patterns of Price Rigidity in an Estimated Multi-Sector Menu-Cost Model?" Review of Economics and Statistics
%
% This code produces  Table B

cd ..\..\Simulations_VC\MS_produits_KR_CalvoPlus

load ..\..\Simulations_VC\MS_produits_KR_CalvoPlus\stat4_alt
param=stat4_alt;
param(143,:)=[0.857199875280086 0.266695001309508 0.0297130383012599 0.694600000000000 0.743983380443812 0.529997861050279 0.0254200000000000 0.0508400000000000 2.77502486296478 0.0139400000000000 0.0254200000000000 0.0393600000000001 1 0.200021250982131 0 0.000693548960074729]


load ..\..\Estimation_param\MS_produits_KR_CalvoPlus\actual_moments_k
weight=actual_moments_k(:,12);
sum(weight);

secteur=actual_moments_k(:,1);

f=param(:,5);
%muc=param(:,2);
f_p=param(:,6);
med=param(:,7);
interq=param(:,8);
kur=param(:,9);
q1=param(:,10);
q2=param(:,11);
q3=param(:,12);

moments_sim=[f f_p med interq kur];
moments_actual=[actual_moments_k(:,2:6)];
size_param=size(moments_sim,2);

%fprintf("Mean Simulated Moments across Products")
mom_mean=(weight'*moments_sim)/sum(weight)

mom_med=ones(1,size_param+2);
stat_sect=moments_sim;
%figure;hist(param_sect(:,3));
v=size(stat_sect,1);
weight_sect=weight;
 if v>0
    for i=1:size(stat_sect,2)
        [sortx,order] = sort(stat_sect(:,i));
        sortw = weight_sect(order);

         midpoint = sum(sortw)/2;
         csumw = cumsum(sortw);
         j = find(csumw<=midpoint,1,'last');
         
        if isempty(j)==1
             j=1;
         end
            if csumw(j) == midpoint
              mom_med(i) = mean(sortx([j j+1]));
            else
                
                mom_med(i) = sortx(j+1);
            end
     mom_med(end)= csumw(end);
     mom_med(end-1)= v;
    end  
 end
%fprintf("Median Simulated Moments across Products")
mom_med


figure;
%P0
subplot(2,3,1);
x=moments_sim(:,1);
y=moments_actual(:,1);


scatter(y, x);

x1=[0  0.2];
y1=x1;
line(x1,y1);

axis([x1 x1]);
ylabel('Freq. sim.') % x-axis label
xlabel('Freq. data') % y-axis label


%MU_c
subplot(2,3,2);
x=moments_sim(:,2);

%x=x(x>0.4);
y=moments_actual(:,2);

%y=y(y>0.2);

scatter(y, x);
x1=[0.4  1];
y1=x1;
line(x1,y1);

axis([x1 x1]);
ylabel('Frac inc. sim.') % x-axis label
xlabel('Frac inc. data') % y-axis label

%MU_c
subplot(2,3,4);
x=moments_sim(:,3);

%x=x(x>0.4);
y=moments_actual(:,3);

%y=y(y>0.2);

scatter(y, x);
x1=[0 0.15];
y1=x1;
line(x1,y1)

axis([x1 x1]);
ylabel('Median sim.') % x-axis label
xlabel('Median data') % y-axis label

%MU_c
subplot(2,3,5);
x=moments_sim(:,4);

%x=x(x>0.4);
y=moments_actual(:,4);

%y=y(y>0.2);

scatter(y, x);
x1=[0 0.25];
y1=x1;
line(x1,y1);
axis([x1 x1])
ylabel('Interq. sim.') % x-axis label
xlabel('Interq. data') % y-axis label

%MU_c
subplot(2,3,6);
x=moments_sim(:,5);

%x=x(x>0.4);
y=moments_actual(:,5);

%y=y(y>0.2);

scatter(y, x);
x1=[0 10];
y1=x1;
line(x1,y1);

axis([x1 x1]);
ylabel('Kurtosis sim.') % x-axis label
xlabel('Kurtosis data') % y-axis label

 print('..\..\..\figures\scatter_act_sim_CPKR.pdf','-dpdf','-fillpage')
 print('..\..\..\figures\scatter_act_sim_CPKR','-depsc')




